<?php 

class Event_MassFormPostSave extends Crud_Event_Handler 
{
	protected $_type = 'postSave';	
	
	public function run($row)
	{
		$id = $this->_getParam('ids');

		$priority = $this->_getParam('priority');
		$hit = $this->_getParam('is_hit') == 1 ? 8 : 1;
		$new = $this->_getParam('is_new') == 1 ? 6 : 1;
		$discout = $this->_getParam('discout') == 1 ? 0.2 : 1;
		$recommended = $this->_getParam('is_recommended') == 1 ? 2 : 1;

		$dataRank = array('priority' => $priority,
						  'is_hit' => $hit, 'is_new' => $new,
						  'is_discout' => $discout,
						  'is_recommended' => $recommended);
		$i = 0;
		foreach($dataRank as $key => $value)
		{
			if($i == 0)
			{
				$i = $value;
			}else{
				$i = $i * $value;
			}
		}
		$count = $this->_getParam('count');
		if($count > 0){
			$i = $i * 50;
		}
		$products = ProductPeer::getInstance();
		foreach($id as $ids)
		{
			$data = array(
				'rank' => $i	
			);
			$products->update($data, '`product`.`id` ='.$ids);
		}

	}
}
